class Solution {
public:
    void dfs(int st, vector<vector<int>> &res, vector<int> &ans, vector<int> &nums)
    {
        if(st == nums.size())
        {
            res.emplace_back(ans);
            return;
        }

        dfs(st + 1, res, ans, nums);

        ans.emplace_back(nums[st]);
        dfs(st + 1, res, ans, nums);
        ans.erase(ans.end() - 1);
    }

    vector<vector<int>> subsets(vector<int>& nums) {
        vector<int> ans;
        vector<vector<int>> res;

        dfs(0, res, ans, nums);
        return res;
    }
};


class Solution {
public:
    vector<vector<int>> ans;
    vector<int> path;

    void dfs(vector<int>& nums, int pos)
    {
        if(pos == nums.size())
        {
            ans.push_back(path);
            return;
        }

        path.push_back(nums[pos]);
        dfs(nums, pos + 1);
        path.pop_back();   

        dfs(nums, pos + 1);
    }

    vector<vector<int>> subsets(vector<int>& nums) {
        dfs(nums, 0);
        return ans;
    }
};


class Solution {
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        int n = nums.size();
        vector<int> path;
        vector<vector<int>> ret;
        auto dfs = [&](this auto&& dfs, int pos)
        {
            if(pos == n) 
            {
                ret.emplace_back(path);
                return;
            }
            dfs(pos + 1);
            path.emplace_back(nums[pos]);
            dfs(pos + 1);
            path.pop_back();
        };
        dfs(0);
        return ret;
    }
};
